/**
  ******************************************************************************
  * @file    Global.h 
  * @author  Dajin Li
  * @version V0.0.1
  * @date    08-08-2015 
  * @brief   This file contains the gobal variable define 
  *          
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; KION(SZ) R&D Center
  *
  * Licensed under KION, (the "License");
  *
  ******************************************************************************
  */

#ifndef  GLOBAL_H
#define GLOBAL_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"


typedef  void (*pFunction)(void);
/* Types */
typedef int32_t            s32;
typedef int16_t            s16;
typedef int8_t             s8;

typedef uint64_t           u64;                     
typedef uint32_t           u32;
typedef uint16_t           u16;
typedef uint8_t            u8;

typedef __IO uint32_t      vu32; 
typedef __IO uint16_t      vu16;
typedef __IO uint8_t       vu8;
typedef enum { FALSE = 0, TRUE  = !FALSE } bool;     



#define TASK_MAX	                            13	                    //Number of tasks,not inclueding watchdog task //used buy watchdog task

#define MAXJ1939DATA 	                        7
#define ApplicationSwAddress                    0x8008000
#define ApplicationEndAddress                   0x8040000
#define BootBISAddress                          0x8000188
#define AppBISAddress                           0x8008188
#define BIT0 		                            0x01
#define BIT1		                            0x02
#define BIT2 		                            0x04
#define BIT3 		                            0x08
#define BIT4 		                            0x10
#define BIT5 		                            0x20
#define BIT6 		                            0x40
#define BIT7 		                            0x80
#define BIT8 		                            0x0100	 
#define BIT9 		                            0x0200	
#define BIT10 	                                0x0400	
#define BIT11 	                                0x0800	
#define BIT12	                                0x1000	
#define BIT13 	                                0x2000
#define BIT14 	                                0x4000	
#define BIT15 	                                0x8000
#define BIT16 	                                0x10000
#define BIT17 	                                0x20000
#define BIT18 	                                0x40000
#define BIT19 	                                0x80000
#define BIT20 	                                0x100000
#define BIT21 	                                0x200000
#define BIT22 	                                0x400000
#define BIT23 	                                0x800000
#define BIT24 	                                0x1000000
#define BIT25 	                                0x2000000
#define BIT26 	                                0x4000000
#define BIT27 	                                0x8000000
#define BIT28 	                                0x10000000
#define BIT29 	                                0x20000000
#define BIT30 	                                0x40000000
#define BIT31 	                                0x80000000

//LCD controlling signals


#define	BUZZER_GPIO_GROUP	                    GPIOA
#define BUZZER_GPIO_PIN		                    GPIO_Pin_12                                                

                                                
// digital input ports detecting the LED Fault codes

#define OFF_CHIP_RTC                              
#define VAR_LENGTH_MASK                        0x00FF
#define READ_WRITE		                       0x8000
#define LIMIT_CHK		                       0x4000
#define SIGNED_VAR		                       0x2000
#define STR_VAR		                           0x1000
#define SAVE_TO_EE		                       0x0800
#define VAR_CLR_SCREEN                         0x0400
#define I_WATCHDOG_TIMEOUT                     2500  // 2s
#define countof(a)                             (sizeof(a) / sizeof(*(a)))
//#define S1D19600 
#define ST7511             
#define MAX(val, val2)                         ((val) < (val2) ? (val2) : (val))
#define MIN(val, val2)                         ((val) < (val2) ? (val) : (val2))
#define ABS(val)                               ((val) < 0 ? -(val) : (val))
extern u8 CAN_Time_Out;
//kwp data params
typedef struct
{
	void *var;				//location y row
	u16 attr;			            //location x column
    u16 ee_addr;
    u16 kwp_id;
	s32 min;				//Icon flash or not
 	s32 max;		    //Icon data
    s32 default_value;
}kwp_data_st;


void Delay (u16 time);
u16 Crc16(u8 *str, u32 length);
s16 lookup_object_id(kwp_data_st *table, s16 length, s32 target);

#endif


